// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

// 云函数入口函数
exports.main = async(event, context) => {
 let {
    type,
    imgUrl
 } = event
 switch (type) {
 case 'shenfenzheng':
 {
 // 识别身份证
 return shenfenzheng(imgUrl)
 }
 case 'jiashizheng':
 {
 // 识别银行卡
 return jiashizheng(imgUrl)
 }
 case 'xingshizheng':
 {
 // 识别行驶证
 return xingshizheng(imgUrl)
 }
 default:
 {
 return
 }
 }
}

//识别身份证
async function shenfenzheng(imgUrl) {
 try {
 const result = await cloud.openapi.ocr.idcard({
      type: 'photo',
      imgUrl: imgUrl
 })
 return result
 } catch (err) {
    console.log(err)
 return err
 }
}
//识别银行卡
async function jiashizheng(imgUrl) {
 try {
 const result = await cloud.openapi.ocr.bankcard({
      type: 'photo',
      imgUrl: imgUrl
 })
 return result
 } catch (err) {
    console.log(err)
 return err
 }
}
//识别行驶证
async function xingshizheng(imgUrl) {
 try {
 const result = await cloud.openapi.ocr.vehicleLicense({
      type: 'photo',
      imgUrl: imgUrl
 })
 return result
 } catch (err) {
    console.log(err)
 return err
 }
}